#include <stdio.h>
#include <stdlib.h>

int *twoDimConvertOneDim(int **arr, int arrSize, int *arrColSize) {
    int rows = arrSize;
    int cols = arrColSize[0];

    int *res = (int *) malloc(sizeof(int) * (rows * cols));
    int index = 0;
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            res[index] = arr[i][j];
            index++;
        }
    }

    return res;
}

int **oneDimConvertTwoDim(int *arr, int rows, int cols) {
    int **res = (int **) malloc(sizeof(int *) * rows);
    for (int i = 0; i < rows; i++) {
        res[i] = (int *) malloc(sizeof(int) * cols);
    }

    for (int index = 0; index < rows * cols; index++) {
        int i = index / cols;
        int j = index % cols;
        res[i][j] = arr[index];
    }
    return res;
}

void printAdj(int **arr, int i, int j, int rows, int cols) {
    int directions[8][2] = {
            {-1, 0}, {1, 0}, {0, -1}, {0, 1},
            {-1, -1}, {-1, 1}, {1, -1}, {1, 1}
     };
    for (int k = 0; k < 8; k++) {
        int row = i + directions[k][0];
        int col = j + directions[k][1];
        if (row < rows && col < cols && row >= 0 && col >= 0) {
            printf("%d\n", arr[row][col]);
        }
    }
}

